local blaze = require "blaze"
local game = require 'club.threecard.texas'

local M = game.ui.element()

M.store_watchers = {
    ingame = {
        ["$"] = blaze.noop,

        ["恢复游戏场景"] = function(self, store, state, args)
            local scene = state.scene
            self.poker_container:clear()
            self.poker_container:mopai(scene.public_card_ids)
        end
    }
}

function M:ctor()
    self.res = 'club.threecard.texas/ui/ingame.b:public_card'
    local container = game.pokerlib.core.poker_container
    local poker_container_config = game.require 'poker_controller.poker_container_config'
    self.poker_container = container.new(poker_container_config.public_config)
end

function M:on_injected(bind)
    self.poker_container:set_gameobject(self.poker_container_obj, true)
end

function M:highlight_card(card_ids)
    local map = {}
    for _, id in ipairs(card_ids) do
        map[id] = true
    end

    for _, poker in ipairs(self.poker_container.hand) do
        if map[poker.data.server_value] then
            poker:highlight()
        else
            poker:gray()
        end
    end
end

return M